from sqlalchemy.orm import Mapped, mapped_column, relationship

from .base import TimedBaseModel


class DeliveryZone(TimedBaseModel):
    __tablename__ = "delivery_zone"
    __mapper_args__ = {"eager_defaults": True}

    id: Mapped[int] = mapped_column(primary_key=True)
    title: Mapped[str]
    users = relationship("User", back_populates="delivery_zone")
    shops = relationship("Shop", back_populates="delivery_zone", cascade="all,delete")

    def __repr__(self):
        return f"<Зона доставки {self.title}>"

    def __str__(self):
        return self.__repr__()
